package com.ruozedata.bigdata.lesson04

object TraitApp {

    def main(args: Array[String]): Unit = {

        val staticMemoryManger = new StaticMemoryManger
        println(staticMemoryManger.maxOnHeapStorageMemory)

    }
}

trait MemoryManger {
    println("~~~~~MemoryManger~~~~~~")
    val name:String

    def maxOnHeapStorageMemory: Long
}

/**
 * 第一个用extend 后面用 with
 * 先 类 后 trait
 * 1 scalac 文件
 * 2 javap -p
 */
class StaticMemoryManger extends MemoryManger with RZException {
    println("~~~StaticMemoryManger~~~")
    override val name: String = "静态内存管理"

    override def maxOnHeapStorageMemory: Long = {
        println(s"$name......")
        100L
    }

    override def exception: Exception = {
        new RuntimeException(s"$name....exception")
    }
}

class StaticMemoryManger2 extends MemoryManger {
    println("~~~StaticMemoryManger~~~2")
    override val name: String = "静态内存管理2"

    override def maxOnHeapStorageMemory: Long = {
        println(s"$name......")
        100L
    }
}

class LoggerZ {
    println("~~~LoggerZ~~~")

    def print(): Unit = {
        println("print log....")
    }
}

trait RZException {
    println("~~RZException~~")

    def exception: Exception
}
